<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Error handling &mdash; The Logtalk Handbook v3.93.0-b01 documentation</title>
      <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=d75fae25" />
      <link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />
      <link rel="stylesheet" type="text/css" href="../_static/css/custom.css?v=396eccfe" />

  
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="../_static/jquery.js?v=5d32c60e"></script>
        <script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
        <script src="../_static/documentation_options.js?v=c8100655"></script>
        <script src="../_static/doctools.js?v=9a2dae69"></script>
        <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../_static/js/theme.js"></script>
    <!-- begin favicon -->
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
    <link rel="manifest" href="/site.webmanifest" />
    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
    <meta name="msapplication-TileColor" content="#355b95" />
    <meta name="theme-color" content="#ffffff" />
    <!-- end favicon -->
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Reflection" href="reflection.html" />
    <link rel="prev" title="Multi-threading programming" href="threads.html" />
   
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../index.html" class="icon icon-home">
            The Logtalk Handbook
              <img src="../_static/logtalk.gif" class="logo" alt="Logo"/>
          </a>
              <div class="version">
                3.93.0
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
    
              <p class="caption" role="heading"><span class="caption-text">Contents</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">User Manual</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="declarative.html">Declarative object-oriented programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="features.html">Main features</a></li>
<li class="toctree-l2"><a class="reference internal" href="nomenclature.html">Nomenclature</a></li>
<li class="toctree-l2"><a class="reference internal" href="messages.html">Messages</a></li>
<li class="toctree-l2"><a class="reference internal" href="objects.html">Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="protocols.html">Protocols</a></li>
<li class="toctree-l2"><a class="reference internal" href="categories.html">Categories</a></li>
<li class="toctree-l2"><a class="reference internal" href="predicates.html">Predicates</a></li>
<li class="toctree-l2"><a class="reference internal" href="inheritance.html">Inheritance</a></li>
<li class="toctree-l2"><a class="reference internal" href="events.html">Event-driven programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="threads.html">Multi-threading programming</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Error handling</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#raising-exceptions">Raising Exceptions</a></li>
<li class="toctree-l3"><a class="reference internal" href="#type-checking">Type-checking</a></li>
<li class="toctree-l3"><a class="reference internal" href="#expected-terms">Expected terms</a></li>
<li class="toctree-l3"><a class="reference internal" href="#compiler-warnings-and-errors">Compiler warnings and errors</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#unknown-entities">Unknown entities</a></li>
<li class="toctree-l4"><a class="reference internal" href="#singleton-variables">Singleton variables</a></li>
<li class="toctree-l4"><a class="reference internal" href="#redefinition-of-prolog-built-in-predicates">Redefinition of Prolog built-in predicates</a></li>
<li class="toctree-l4"><a class="reference internal" href="#redefinition-of-logtalk-built-in-predicates">Redefinition of Logtalk built-in predicates</a></li>
<li class="toctree-l4"><a class="reference internal" href="#redefinition-of-logtalk-built-in-methods">Redefinition of Logtalk built-in methods</a></li>
<li class="toctree-l4"><a class="reference internal" href="#misspell-calls-of-local-predicates">Misspell calls of local predicates</a></li>
<li class="toctree-l4"><a class="reference internal" href="#portability-warnings">Portability warnings</a></li>
<li class="toctree-l4"><a class="reference internal" href="#deprecated-elements">Deprecated elements</a></li>
<li class="toctree-l4"><a class="reference internal" href="#missing-directives">Missing directives</a></li>
<li class="toctree-l4"><a class="reference internal" href="#duplicated-directives">Duplicated directives</a></li>
<li class="toctree-l4"><a class="reference internal" href="#duplicated-clauses">Duplicated clauses</a></li>
<li class="toctree-l4"><a class="reference internal" href="#goals-that-are-always-true-or-false">Goals that are always true or false</a></li>
<li class="toctree-l4"><a class="reference internal" href="#trivial-fails">Trivial fails</a></li>
<li class="toctree-l4"><a class="reference internal" href="#suspicious-calls">Suspicious calls</a></li>
<li class="toctree-l4"><a class="reference internal" href="#lambda-variables">Lambda variables</a></li>
<li class="toctree-l4"><a class="reference internal" href="#redefinition-of-predicates-declared-in-uses-2-or-use-module-2-directives">Redefinition of predicates declared in <code class="docutils literal notranslate"><span class="pre">uses/2</span></code> or <code class="docutils literal notranslate"><span class="pre">use_module/2</span></code> directives</a></li>
<li class="toctree-l4"><a class="reference internal" href="#other-warnings-and-errors">Other warnings and errors</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#runtime-errors">Runtime errors</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#logtalk-built-in-predicates">Logtalk built-in predicates</a></li>
<li class="toctree-l4"><a class="reference internal" href="#logtalk-built-in-methods">Logtalk built-in methods</a></li>
<li class="toctree-l4"><a class="reference internal" href="#message-sending">Message sending</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="reflection.html">Reflection</a></li>
<li class="toctree-l2"><a class="reference internal" href="programming.html">Writing and running applications</a></li>
<li class="toctree-l2"><a class="reference internal" href="printing.html">Printing messages and asking questions</a></li>
<li class="toctree-l2"><a class="reference internal" href="expansion.html">Term and goal expansion</a></li>
<li class="toctree-l2"><a class="reference internal" href="documenting.html">Documenting</a></li>
<li class="toctree-l2"><a class="reference internal" href="debugging.html">Debugging</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance.html">Performance</a></li>
<li class="toctree-l2"><a class="reference internal" href="installing.html">Installing Logtalk</a></li>
<li class="toctree-l2"><a class="reference internal" href="migration.html">Prolog integration and migration</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../refman/index.html">Reference Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../faq/index.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../devtools/index.html">Developer Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a></li>
<li class="toctree-l1"><a class="reference internal" href="../ports/index.html">Ports</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributions/index.html">Contributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
<li class="toctree-l1"><a class="reference internal" href="../bibliography.html">Bibliography</a></li>
<li class="toctree-l1"><a class="reference internal" href="../genindex.html">Index</a></li>
</ul>

    <p class="caption"><span class="caption-text">External Contents</span></p>
    <ul>
    <li class="toctree-l1"><a class="reference internal" href="../../apis/index.html">APIs</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://logtalk.org">Logtalk website</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://github.com/LogtalkDotOrg/logtalk3">GitHub repo</a></li>
    </ul>
  
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">The Logtalk Handbook</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="index.html">User Manual</a></li>
      <li class="breadcrumb-item active">Error handling</li>
      <li class="wy-breadcrumbs-aside">
              <a href="https://github.com/LogtalkDotOrg/logtalk3/blob/master/docs/handbook/sources/userman/errors.rst" class="fa fa-github"> Edit on GitHub</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="error-handling">
<span id="errors-errors"></span><h1>Error handling<a class="headerlink" href="#error-handling" title="Link to this heading"></a></h1>
<p>Error handling is accomplished in Logtalk by using the standard <code class="docutils literal notranslate"><span class="pre">catch/3</span></code>
and <code class="docutils literal notranslate"><span class="pre">throw/1</span></code> predicates <a class="reference internal" href="../bibliography.html#iso95" id="id1"><span>[ISO95]</span></a> together with a set of built-in methods
that simplify generating errors decorated with expected context.</p>
<p>Errors thrown by Logtalk have, whenever possible, the following format:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>error(<span class="nv">Error</span>, logtalk(<span class="nv">Goal</span>, <span class="nv">ExecutionContext</span>))
</pre></div>
</div>
<p>In this exception term, <code class="docutils literal notranslate"><span class="pre">Goal</span></code> is the goal that triggered the error
<code class="docutils literal notranslate"><span class="pre">Error</span></code> and <code class="docutils literal notranslate"><span class="pre">ExecutionContext</span></code> is the context in which <code class="docutils literal notranslate"><span class="pre">Goal</span></code> is
called. For example:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>error(
    <span class="k">permission_error</span>(modify,private_predicate,p<span class="o">/</span><span class="m">0</span>),
    logtalk(foo<span class="o">::</span><span class="k">abolish</span>(p<span class="o">/</span><span class="m">0</span>), <span class="nv">_</span>)
)
</pre></div>
</div>
<p>Note, however, that <code class="docutils literal notranslate"><span class="pre">Goal</span></code> and <code class="docutils literal notranslate"><span class="pre">ExecutionContext</span></code> can be unbound or only
partially instantiated when the corresponding information is not available
(e.g., due to compiler optimizations that throw away the necessary error context
information). The <code class="docutils literal notranslate"><span class="pre">ExecutionContext</span></code> argument is an opaque term that
can be decoded using the
<a class="reference external" href="../../apis/logtalk_0.html#logtalk-0-execution-context-7" title="(in Logtalk APIs v3.93.0)"><span class="xref std std-ref">logtalk::execution_context/7</span></a> predicate.</p>
<section id="raising-exceptions">
<h2>Raising Exceptions<a class="headerlink" href="#raising-exceptions" title="Link to this heading"></a></h2>
<p>The <a class="reference internal" href="../refman/methods/error_handling_methods.html#error-handling-methods"><span class="std std-ref">error handling section</span></a> in the reference
manual lists a set of convenient built-in methods that generate <code class="docutils literal notranslate"><span class="pre">error/2</span></code>
exception terms with the expected context argument. For example, instead of
manually constructing a type error as in:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>...,
<span class="k">context</span>(<span class="nv">Context</span>),
<span class="k">throw</span>(error(<span class="k">type_error</span>(atom, <span class="m">42</span>), <span class="nv">Context</span>)).
</pre></div>
</div>
<p>we can simply write:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>...,
<span class="k">type_error</span>(atom, <span class="m">42</span>).
</pre></div>
</div>
<p>The provided error built-in methods cover all standard error types found in
the ISO Prolog Core standard.</p>
</section>
<section id="type-checking">
<h2>Type-checking<a class="headerlink" href="#type-checking" title="Link to this heading"></a></h2>
<p>One of the most common cases where errors may be generated is when
type-checking predicate arguments and input data before processing it.
The standard library includes a <a class="reference external" href="../../apis/type_0.html#type-0" title="(in Logtalk APIs v3.93.0)"><span class="xref std std-ref">type</span></a> object that
defines an extensive set of types, together with predicates for validating
and checking terms. The set of types is user extensible. New types can
be defined by adding clauses for the <code class="docutils literal notranslate"><span class="pre">type/1</span></code> and <code class="docutils literal notranslate"><span class="pre">check/2</span></code> multifile
predicates. For example, assume that we want to be able to check
<em>temperatures</em> expressed in Celsius, Fahrenheit, or Kelvin scales. We
start by declaring (in an object or category) the new type:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="p">:- </span><span class="k">multifile</span>(type<span class="o">::</span>type<span class="o">/</span><span class="m">1</span>).
type<span class="o">::</span>type(temperature(<span class="nv">_Unit</span>)).
</pre></div>
</div>
<p>Next, we need to define the actual code that would verify that a temperature
is valid. As the different scales use a different value for absolute zero,
we can write:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="p">:- </span><span class="k">multifile</span>(type<span class="o">::</span>check<span class="o">/</span><span class="m">2</span>).
type<span class="o">::</span>check(temperature(<span class="nv">Unit</span>), <span class="nv">Term</span>) <span class="o">:-</span>
    check_temperature(<span class="nv">Unit</span>, <span class="nv">Term</span>).

<span class="c">% given that temperature has only a lower bound, we make use of the library</span>
<span class="c">% property/2 type to define the necessary test expression for each unit</span>
check_temperature(celsius, <span class="nv">Term</span>) <span class="o">:-</span>
    type<span class="o">::</span>check(property(float, [<span class="nv">Temperature</span>]<span class="o">&gt;&gt;</span>(<span class="nv">Temperature</span> <span class="o">&gt;=</span> <span class="o">-</span><span class="m">273.15</span>)), <span class="nv">Term</span>).
check_temperature(fahrenheit, <span class="nv">Term</span>) <span class="o">:-</span>
    type<span class="o">::</span>check(property(float, [<span class="nv">Temperature</span>]<span class="o">&gt;&gt;</span>(<span class="nv">Temperature</span> <span class="o">&gt;=</span> <span class="o">-</span><span class="m">459.67</span>)), <span class="nv">Term</span>).
check_temperature(kelvin, <span class="nv">Term</span>) <span class="o">:-</span>
    type<span class="o">::</span>check(property(float, [<span class="nv">Temperature</span>]<span class="o">&gt;&gt;</span>(<span class="nv">Temperature</span> <span class="o">&gt;=</span> <span class="m">0.0</span>)), <span class="nv">Term</span>).
</pre></div>
</div>
<p>With this definition, a term is first checked that it is a float value before
checking that it is in the expected open interval. But how do we use this new
type? If we just want to test if a temperature is valid, we can write:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>..., type<span class="o">::</span>valid(temperature(celsius), <span class="m">42.0</span>), ...
</pre></div>
</div>
<p>The <a class="reference external" href="../../apis/type_0.html#type-0-valid-2" title="(in Logtalk APIs v3.93.0)"><span class="xref std std-ref">type::valid/2</span></a> predicate succeeds or fails
depending on the second argument being of the type specified in the first
argument. If instead of success or failure we want to generate an error for
invalid values, we can use the <a class="reference external" href="../../apis/type_0.html#type-0-check-2" title="(in Logtalk APIs v3.93.0)"><span class="xref std std-ref">type::check/2</span></a>
predicate instead:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>..., type<span class="o">::</span>check(temperature(celsius), <span class="m">42.0</span>), ...
</pre></div>
</div>
<p>If we require an <code class="docutils literal notranslate"><span class="pre">error/2</span></code> exception term with the error context, we can
use instead the <a class="reference external" href="../../apis/type_0.html#type-0-check-3" title="(in Logtalk APIs v3.93.0)"><span class="xref std std-ref">type::check/3</span></a> predicate:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>...,
<span class="k">context</span>(<span class="nv">Context</span>),
type<span class="o">::</span>check(temperature(celsius), <span class="m">42.0</span>, <span class="nv">Context</span>),
...
</pre></div>
</div>
<p>Note that <code class="docutils literal notranslate"><span class="pre">context/1</span></code> calls are inlined and messages to the library
<code class="docutils literal notranslate"><span class="pre">type</span></code> object use <a class="reference internal" href="../glossary.html#term-static-binding"><span class="xref std std-term">static binding</span></a> when compiling with the
<a class="reference internal" href="programming.html#flag-optimize"><span class="std std-ref">optimize flag</span></a> turned on, thus enabling efficient
type-checking.</p>
</section>
<section id="expected-terms">
<h2>Expected terms<a class="headerlink" href="#expected-terms" title="Link to this heading"></a></h2>
<p>Support for representing and handling <em>expected terms</em> is provided by the
<a class="reference internal" href="../libraries/expecteds.html"><span class="doc">expecteds</span></a> library. Expected terms allow deferring errors
to later stages of an application in lieu to raising an exception as
soon as an error is detected.</p>
</section>
<section id="compiler-warnings-and-errors">
<h2>Compiler warnings and errors<a class="headerlink" href="#compiler-warnings-and-errors" title="Link to this heading"></a></h2>
<p>The current Logtalk compiler uses the standard <code class="docutils literal notranslate"><span class="pre">read_term/3</span></code> built-in
predicate to read and compile a Logtalk source file. This improves the
compatibility with <a class="reference internal" href="../glossary.html#term-backend-Prolog-compiler"><span class="xref std std-term">backend Prolog compilers</span></a>
and their proprietary syntax extensions and standard compliance quirks. But one
consequence of this design choice is that invalid Prolog terms or syntax errors
may abort the compilation process with limited information given to the user
(due to the inherent limitations of the <code class="docutils literal notranslate"><span class="pre">read_term/3</span></code> predicate).</p>
<p>Assuming that all the terms in a source file are valid, there is a set of
errors and potential errors, described below, that the compiler will try
to detect and report, depending on the used compiler flags (see the
<a class="reference internal" href="programming.html#programming-flags"><span class="std std-ref">Compiler flags</span></a> section of this manual on lint flags for details).</p>
<section id="unknown-entities">
<span id="errors-unknown"></span><h3>Unknown entities<a class="headerlink" href="#unknown-entities" title="Link to this heading"></a></h3>
<p>The Logtalk compiler warns about any referenced entity that is not
currently loaded. The warning may reveal a misspelled entity name or just
an entity that will be loaded later. Out-of-order loading should be
avoided when possible as it prevents some code optimizations, such as
<a class="reference internal" href="../glossary.html#term-static-binding"><span class="xref std std-term">static binding</span></a> of messages to methods.</p>
</section>
<section id="singleton-variables">
<span id="errors-singletons"></span><h3>Singleton variables<a class="headerlink" href="#singleton-variables" title="Link to this heading"></a></h3>
<p>Singleton variables in a clause are often misspelled variables and, as
such, are one of the most common errors when programming in Prolog.
Assuming that the <a class="reference internal" href="../glossary.html#term-backend-Prolog-compiler"><span class="xref std std-term">backend Prolog compiler</span></a> implementation of the
<code class="docutils literal notranslate"><span class="pre">read_term/3</span></code> predicate supports the standard <code class="docutils literal notranslate"><span class="pre">singletons/1</span></code>
option, the compiler warns about any singleton variable found while
compiling a source file.</p>
</section>
<section id="redefinition-of-prolog-built-in-predicates">
<span id="errors-prolog"></span><h3>Redefinition of Prolog built-in predicates<a class="headerlink" href="#redefinition-of-prolog-built-in-predicates" title="Link to this heading"></a></h3>
<p>The Logtalk compiler will warn us of any redefinition of a Prolog
built-in predicate inside an object or category. Sometimes the redefinition
is intended. In other cases, the user may not be aware that a particular
<a class="reference internal" href="../glossary.html#term-backend-Prolog-compiler"><span class="xref std std-term">backend Prolog compiler</span></a> may already provide the predicate
as a built-in predicate or may want to ensure code portability among
several Prolog compilers with different sets of built-in predicates.</p>
</section>
<section id="redefinition-of-logtalk-built-in-predicates">
<span id="errors-redefinition-predicates"></span><h3>Redefinition of Logtalk built-in predicates<a class="headerlink" href="#redefinition-of-logtalk-built-in-predicates" title="Link to this heading"></a></h3>
<p>Similar to the redefinition of Prolog built-in predicates, the Logtalk
compiler will warn us if we try to redefine a Logtalk built-in. But the
redefinition will probably be an error in most (if not all) cases.</p>
</section>
<section id="redefinition-of-logtalk-built-in-methods">
<span id="errors-redefinition-methods"></span><h3>Redefinition of Logtalk built-in methods<a class="headerlink" href="#redefinition-of-logtalk-built-in-methods" title="Link to this heading"></a></h3>
<p>An error will be thrown if we attempt to redefine a Logtalk built-in
method inside an entity. The default behavior is to report the error and
abort the compilation of the offending entity.</p>
</section>
<section id="misspell-calls-of-local-predicates">
<span id="errors-misspell"></span><h3>Misspell calls of local predicates<a class="headerlink" href="#misspell-calls-of-local-predicates" title="Link to this heading"></a></h3>
<p>A warning will be reported if Logtalk finds (in the body of a predicate
definition) a call to a local predicate that is not defined, built-in
(either in Prolog or in Logtalk) or declared dynamic. In most cases
these calls are simple misspell errors.</p>
</section>
<section id="portability-warnings">
<span id="errors-portability"></span><h3>Portability warnings<a class="headerlink" href="#portability-warnings" title="Link to this heading"></a></h3>
<p>A warning will be reported if a predicate clause contains a call to a
non-standard built-in predicate or arithmetic function. Portability
warnings are also reported for non-standard flags or flag values. These
warnings often cannot be avoided due to the limited scope of the ISO
Prolog standard.</p>
</section>
<section id="deprecated-elements">
<span id="errors-deprecated"></span><h3>Deprecated elements<a class="headerlink" href="#deprecated-elements" title="Link to this heading"></a></h3>
<p>A warning will be reported if a deprecated directive, control construct,
or predicate is used. These warnings should be fixed as soon as possible,
as support for any deprecated features will likely be discontinued in
future versions.</p>
</section>
<section id="missing-directives">
<span id="errors-missing-directives"></span><h3>Missing directives<a class="headerlink" href="#missing-directives" title="Link to this heading"></a></h3>
<p>A warning will be reported for any missing dynamic, discontiguous,
meta-predicate, and public predicate directive.</p>
</section>
<section id="duplicated-directives">
<span id="errors-duplicated-directives"></span><h3>Duplicated directives<a class="headerlink" href="#duplicated-directives" title="Link to this heading"></a></h3>
<p>A warning will be reported for any duplicated scope, multifile, dynamic,
discontiguous, meta-predicate, and meta-non-terminal directives. Note
that conflicting directives for the same predicate are handled as
errors, not as duplicated directive warnings.</p>
</section>
<section id="duplicated-clauses">
<span id="errors-duplicated-clauses"></span><h3>Duplicated clauses<a class="headerlink" href="#duplicated-clauses" title="Link to this heading"></a></h3>
<p>A warning will be reported for any duplicated entity clauses. This check
is computationally heavy, however, and usually turned off by default.</p>
</section>
<section id="goals-that-are-always-true-or-false">
<span id="errors-always-true-or-false-goals"></span><h3>Goals that are always true or false<a class="headerlink" href="#goals-that-are-always-true-or-false" title="Link to this heading"></a></h3>
<p>A warning will be reported for any goal that is always true or false.
This is usually caused by typos in the code. For example, writing
<code class="docutils literal notranslate"><span class="pre">X</span> <span class="pre">==</span> <span class="pre">y</span></code> instead of <code class="docutils literal notranslate"><span class="pre">X</span> <span class="pre">==</span> <span class="pre">Y</span></code>.</p>
</section>
<section id="trivial-fails">
<span id="errors-trivial-fails"></span><h3>Trivial fails<a class="headerlink" href="#trivial-fails" title="Link to this heading"></a></h3>
<p>A warning will be reported for any call to a local static predicate with
no matching clause.</p>
</section>
<section id="suspicious-calls">
<span id="errors-suspicious-calls"></span><h3>Suspicious calls<a class="headerlink" href="#suspicious-calls" title="Link to this heading"></a></h3>
<p>A warning will be reported for calls that are syntactically correct but most
likely a semantic error. An example is <a class="reference internal" href="../refman/control/send_to_self_1.html#control-send-to-self-1"><span class="std std-ref">(::)/1</span></a> calls in
clauses that apparently are meant to implement recursive predicate definitions
where the user intention is to call the local predicate definition.</p>
</section>
<section id="lambda-variables">
<span id="errors-lambda-variables"></span><h3>Lambda variables<a class="headerlink" href="#lambda-variables" title="Link to this heading"></a></h3>
<p>A warning will be reported for <a class="reference internal" href="../glossary.html#term-lambda-expression"><span class="xref std std-term">lambda expressions</span></a>
with unclassified variables (not listed as either <a class="reference internal" href="../glossary.html#term-lambda-free-variable"><span class="xref std std-term">lambda free</span></a>
or <a class="reference internal" href="../glossary.html#term-lambda-parameter"><span class="xref std std-term">lambda parameter</span></a> variables), for variables playing a dual role
(as both lambda free and lambda parameter variables), and for lambda parameters
used elsewhere in a clause.</p>
</section>
<section id="redefinition-of-predicates-declared-in-uses-2-or-use-module-2-directives">
<span id="errors-predicate-redefinition"></span><h3>Redefinition of predicates declared in <code class="docutils literal notranslate"><span class="pre">uses/2</span></code> or <code class="docutils literal notranslate"><span class="pre">use_module/2</span></code> directives<a class="headerlink" href="#redefinition-of-predicates-declared-in-uses-2-or-use-module-2-directives" title="Link to this heading"></a></h3>
<p>A error will be reported for any attempt to define locally a predicate
that is already declared in an <a class="reference internal" href="../refman/directives/uses_2.html#directives-uses-2"><span class="std std-ref">uses/2</span></a> or
<a class="reference internal" href="../refman/directives/use_module_2.html#directives-use-module-2"><span class="std std-ref">use_module/2</span></a> directive.</p>
</section>
<section id="other-warnings-and-errors">
<span id="errors-others"></span><h3>Other warnings and errors<a class="headerlink" href="#other-warnings-and-errors" title="Link to this heading"></a></h3>
<p>The Logtalk compiler will throw an error if it finds a predicate clause
or a directive that cannot be parsed. The default behavior is to report
the error and abort the compilation.</p>
</section>
</section>
<section id="runtime-errors">
<span id="errors-runtime"></span><h2>Runtime errors<a class="headerlink" href="#runtime-errors" title="Link to this heading"></a></h2>
<p>This section briefly describes runtime errors that result from misuse of
Logtalk built-in predicates, built-in methods, or from message-sending.
For a complete and detailed description of runtime errors, please consult
the Reference Manual.</p>
<section id="logtalk-built-in-predicates">
<span id="errors-predicates"></span><h3>Logtalk built-in predicates<a class="headerlink" href="#logtalk-built-in-predicates" title="Link to this heading"></a></h3>
<p>Most Logtalk built-in predicates check the type and mode of the calling
arguments, throwing an exception in case of misuse.</p>
</section>
<section id="logtalk-built-in-methods">
<span id="errors-methods"></span><h3>Logtalk built-in methods<a class="headerlink" href="#logtalk-built-in-methods" title="Link to this heading"></a></h3>
<p>Most Logtalk built-in method check the type and mode of the calling
arguments, throwing an exception in case of misuse.</p>
</section>
<section id="message-sending">
<span id="errors-sending"></span><h3>Message sending<a class="headerlink" href="#message-sending" title="Link to this heading"></a></h3>
<p>The message-sending mechanisms always check if the receiver of a message
is a defined object and if the message corresponds to a declared
predicate within the scope of the sender. The built-in protocol
<a class="reference external" href="../../apis/forwarding_0.html#forwarding-0" title="(in Logtalk APIs v3.93.0)"><span class="xref std std-ref">forwarding</span></a> declares a predicate,
<a class="reference internal" href="../refman/methods/forward_1.html#methods-forward-1"><span class="std std-ref">forward/1</span></a>, which is automatically called (if defined) by
the runtime for any message that the receiving object does not understand.
The usual definition for this error handler is to delegate or forward the
message to another object that might be able to answer it:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="k">forward</span>(<span class="nv">Message</span>) <span class="o">:-</span>
    <span class="c">% forward the message while preserving the sender</span>
    [<span class="nv">Object</span><span class="o">::</span><span class="nv">Message</span>].
</pre></div>
</div>
<p>If preserving the original sender is not required, this definition can
be simplified to:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="k">forward</span>(<span class="nv">Message</span>) <span class="o">:-</span>
    <span class="nv">Object</span><span class="o">::</span><span class="nv">Message</span>.
</pre></div>
</div>
<p>More sophisticated definitions are, of course, possible.</p>
</section>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="threads.html" class="btn btn-neutral float-left" title="Multi-threading programming" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="reflection.html" class="btn btn-neutral float-right" title="Reflection" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 1998-2025, Paulo Moura.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>